<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-08-31 11:00:35
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" other
-->

<template>
  <sc-VxeTable
    ref="xGrid"
    :gridEvts="gridEvents"
    :gridOps="gridOps"
    :tablecode="'pro_opencard_order'"
    :url="api.pro.OpenCard.order"
    :params="{ 'material.pro_allow': 1 }"
  >
  </sc-VxeTable>
  <save-dig
    v-if="dialog.save"
    ref="save"
    @success="handleSuccess"
    @closed="dialog.save = false"
  ></save-dig>
</template>

<script>
export default {
  name: "pro_pot_index",
};
</script>

<script setup>
import { nextTick, ref } from "vue";
import saveDig from "./savepro";
import api from "@/api";
import tool from "@/utils/tool";
const dialog = ref({
  save: false,
});
const xGrid = ref({});
const save = ref({});
const handleSuccess = () => {
  dialog.value.save = false;
  xGrid.value.refresh();
};
const gridOps = {
  columns: [
    {
      field: "company_name",
      className: "red",
    },
    {
      field: "process.name",
      className: "red",
    },
    {
      field: "material.name",
      className: "blue",
    },
  ],
  rowClassName: ({ row }) => {
    let time = new Date(row.potdate).getTime();
    let nowtime = new Date(tool.SYS_DATE()).getTime();
    if (time == nowtime) return "backgroudYellow";
  },
};
const edit = function (rows) {
  let customer = null,
    errmes = [];

  let ids = rows.map((v) => {
    if (customer == null) {
      customer = v.customer_id;
    } else if (customer != v.customer_id) {
      errmes.push(errmes.length + 1 + "、批量开卡必须选择统一客户！！");
    }
    return v.id;
  });
  if (ids == null) {
    errmes.push(errmes.length + 1 + "、必须选择明细！！！");
  }
  if (errmes.length > 0) {
    throw errmes.join(";");
  }
  dialog.value.save = true;
  nextTick(() => {
    save.value.setData(ids).open();
  });
};
const gridEvents = {
  cellDblclick: function ({ row }) {
    edit([row]);
  },
  edit: function ({ button }) {
    edit(button.selectRecords);
  },
};
</script>
